#include "sk_storage/sst.hpp"


namespace sk_storage {

SstFormat::SstFormat() {

}

Status SstFormat::Pack(const std::map<std::string, std::string>& mp_, std::string& output) {
  output = "";
  for (const auto & item : mp_) {
    output.append(item.first);
    output.push_back('|');
    output.append(item.second);
    output.push_back('\n');
  }
  return OK;
}

Status SstFormat::Unpack(const std::string& input, std::map<std::string, std::string>& mp_) {
  mp_.clear();
  std::string key, value;
  bool iskey = true;
  for(int i = 0;i < input.size(); i++) {
    if (input[i] == '\n') {
      mp_[key] = value;
      key = "";
      value = "";
      iskey = true;
    } else if (input[i] == '|') {
      iskey = false;
    } else {
      if (iskey) {
        key.push_back(input[i]);
      } else {
        value.push_back(input[i]);
      }
    }
  }
  return OK;
}

SstFormat::~SstFormat() {

}

} // namespace sk_storage
